package com.threaddemo4;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class ExceptionallyDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("F1 " + Thread.currentThread().getName());
            int i = 10 / 0;
            return "F1 返回值";
        });
        //上一个任务 执行有异常 参数就是异常信息
        CompletableFuture<String> ea = f1.exceptionally(e->{
            System.out.println("上一个任务的异常信息 = " + e.getMessage());
            return "异常返回值";
        });

        System.out.println("f1 = " + f1.get());
        System.out.println("ea = " + ea.get());

    }
}
